package com.gadgets.busi.bm03;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-12-18
 *
 */
public class FileLoad {

    private final String[] REGIX = {"TP22014"};

    private static final Logger logger = LoggerFactory.getLogger(FileLoad.class);

    public void FileLoad(File rootPath){
        if(rootPath.isDirectory()){
            File[] sonFile = rootPath.listFiles();
            for (File son : sonFile) {
                FileLoad(son);
            }
        }else {
            System.out.println("文件:"+rootPath);
        }
    }

    public boolean readFile(File target){
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(target);
            BufferedReader reader = new BufferedReader(new InputStreamReader(fileInputStream));
            String line = "";
            while (null!=(line=reader.readLine())){
                for (String regix : REGIX) {
                    if(line.contains(regix)){
                        return true;
                    }
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        File file = new File("C:\\Users\\xiujunqing\\Downloads\\BBSP4.0");
        FileLoad fileLoad = new FileLoad();
        fileLoad.FileLoad(file);
    }

}
